package com.xinqi.common.base.utils.tree;

import com.google.common.collect.Lists;

import java.util.Comparator;
import java.util.List;

/**
 * 树工具
 *
 * @author linkai
 * @date 2022/11/25
 */
public interface Trees {

    static <T, P> List<T> tree(List<T> list, P initParent) {
        return tree(list, initParent, null);
    }

    static <T, P> List<T> tree(List<T> list, P initParent, Comparator<T> comparator) {
        if (list == null || list.isEmpty()) {
            return Lists.newArrayList();
        }
        TreeHelp<T, P> help = TreeHelp.<T, P>builder().setList(list).setComparator(comparator).setId("id")
            .setChildren("children").setParent("parentId").build();
        return help.handle(initParent);
    }

}
